// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   registerInit_ok.java

package finance.fixed_assets;

import include.get_name_from_ID.getNameFromID;
import include.nseer_cookie.counter;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;

public class registerInit_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;

	public registerInit_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		nseer_db_backup1 finance_db = new nseer_db_backup1(dbApplication);
		getNameFromID getNameFromID = new getNameFromID();
		PrintWriter out = response.getWriter();
		try
		{
			if (finance_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
				counter count = new counter(dbApplication);
				ValidataNumber validata = new ValidataNumber();
				int err_count = 0;
				String type_name = request.getParameter("type_name");
				String file_id = request.getParameter("file_id");
				String file_name = request.getParameter("file_name");
				String addway = request.getParameter("addway");
				String department = request.getParameter("department");
				String specification = request.getParameter("specification");
				String deposit_place = request.getParameter("deposit_place");
				String status = request.getParameter("status");
				String calway = request.getParameter("calway");
				String start_time = request.getParameter("start_time");
				String lifecycle = request.getParameter("lifecycle");
				String work_total = request.getParameter("work_total");
				String work_sum = request.getParameter("work_sum");
				String work_unit = request.getParameter("work_unit");
				String currency = request.getParameter("currency");
				String original_value = request.getParameter("original_value");
				String remnant_value = request.getParameter("remnant_value");
				String remnant_value_rate = request.getParameter("remnant_value_rate");
				String unit_cal = request.getParameter("unit_cal");
				String caled_month = request.getParameter("caled_month");
				String caled_sum = request.getParameter("caled_sum");
				String caled_subtotal_rate = request.getParameter("caled_subtotal_rate");
				String caled_subtotal = request.getParameter("caled_subtotal");
				String net_value = request.getParameter("net_value");
				String cal_file_name = request.getParameter("cal_file_name");
				String sql = "";
				ResultSet rs = null;
				if (type_name.equals("") || file_id.equals("") || file_name.equals("") || addway.equals("") || department.equals("") || start_time.equals("") || original_value.equals(""))
				{
					err_count = 1;
				} else
				{
					sql = (new StringBuilder("select file_id from finance_fa_file where file_id='")).append(file_id).append("'").toString();
					rs = finance_db.executeQuery(sql);
					if (rs.next())
					{
						err_count = 2;
					} else
					{
						sql = (new StringBuilder("select file_id from finance_fa_file where file_name='")).append(file_name).append("'").toString();
						rs = finance_db.executeQuery(sql);
						if (rs.next())
						{
							err_count = 3;
						} else
						{
							String time = "";
							sql = "select start_time from finance_account_period where account_finished_tag='0' order by account_period";
							rs = finance_db.executeQuery(sql);
							if (rs.next())
								time = rs.getString("start_time");
							Date date1 = formatter.parse(time);
							Date date2 = formatter.parse(start_time);
							if (date1.getTime() <= date2.getTime())
								err_count = 4;
							else
							if (!validata.validata(original_value) || !validata.validata(caled_month) || !validata.validata(caled_sum) || !validata.validata(net_value) || !validata.validata(remnant_value))
								err_count = 5;
							else
							if (!validata.validata(caled_subtotal_rate) && !caled_subtotal_rate.equals("undefined"))
								err_count = 6;
							else
							if (!validata.validata(unit_cal) && !unit_cal.equals("undefined"))
								err_count = 7;
						}
					}
				}
				if (err_count == 0)
				{
					int filenum = count.read((String)dbSession.getAttribute("unit_db_name"), "financefafilecount");
					count.write((String)dbSession.getAttribute("unit_db_name"), "financefafilecount", filenum);
					String addway_id = addway.substring(0, addway.indexOf(" "));
					String addway_name = addway.substring(addway.indexOf(" ") + 1);
					String type_id = type_name.substring(0, type_name.indexOf(" "));
					type_name = type_name.substring(type_name.indexOf(" ") + 1);
					String department_id = department.substring(0, department.indexOf(" "));
					String department_name = department.substring(department.indexOf(" ") + 1);
					if (!caled_subtotal_rate.equals("") && unit_cal.equals("undefined"))
						sql = (new StringBuilder("insert into finance_fa_file(card_id,type_id,type_name,file_id,file_name,addway_id,addway_name,department_id,department_name,specification,deposit_place,status_id,calway_id,start_time,lifecycle,currency,original_value,remnant_value,remnant_value_rate,caled_month,caled_sum,cal_subtotal,cal_subtotal_rate,net_value,cal_file_name) values('")).append(filenum).append("','").append(type_id).append("','").append(type_name).append("','").append(file_id).append("','").append(file_name).append("','").append(addway_id).append("','").append(addway_name).append("','").append(department_id).append("','").append(department_name).append("','").append(specification).append("','").append(deposit_place).append("','").append(status).append("','").append(calway).append("','").append(start_time).append("','").append(lifecycle).append("','").append(currency).append("','").append(original_value).append("','").append(remnant_value).append("','").append(remnant_value_rate).append("','").append(caled_month).append("','").append(caled_sum).append("','").append(caled_subtotal).append("','").append(caled_subtotal_rate).append("','").append(net_value).append("','").append(cal_file_name).append("')").toString();
					else
						sql = (new StringBuilder("insert into finance_fa_file(card_id,type_id,type_name,file_id,file_name,addway_id,addway_name,department_id,department_name,specification,deposit_place,status_id,calway_id,start_time,lifecycle,work_total,work_sum,work_unit,currency,original_value,remnant_value,remnant_value_rate,caled_month,caled_sum,cal_subtotal,unit_cal,net_value,cal_file_name) values('")).append(filenum).append("','").append(type_id).append("','").append(type_name).append("','").append(file_id).append("','").append(file_name).append("','").append(addway_id).append("','").append(addway_name).append("','").append(department_id).append("','").append(department_name).append("','").append(specification).append("','").append(deposit_place).append("','").append(status).append("','").append(calway).append("','").append(start_time).append("','").append(lifecycle).append("','").append(work_total).append("','").append(work_sum).append("','").append(work_unit).append("','").append(currency).append("','").append(original_value).append("','").append(remnant_value).append("','").append(remnant_value_rate).append("','").append(caled_month).append("','").append(caled_sum).append("','").append(caled_subtotal).append("','").append(unit_cal).append("','").append(net_value).append("','").append(cal_file_name).append("')").toString();
					finance_db.executeUpdate(sql);
					String sql1 = (new StringBuilder("update finance_config_assets_kind set delete_tag='1' where file_id='")).append(type_id).append("'").toString();
					finance_db.executeUpdate(sql1);
					sql1 = (new StringBuilder("update finance_config_assets_fluctuationway set delete_tag='1' where file_id='")).append(addway_id).append("'").toString();
					finance_db.executeUpdate(sql1);
					sql1 = (new StringBuilder("update finance_config_file_kind set delete_tag='1' where file_id='")).append(cal_file_name.split(" ")[0]).append("'").toString();
					finance_db.executeUpdate(sql1);
					sql1 = (new StringBuilder("update hr_config_file_kind set delete_tag='1' where file_id='")).append(department_id).append("'").toString();
					finance_db.executeUpdate(sql1);
					out.println(err_count);
				} else
				{
					out.println(err_count);
				}
				finance_db.commit();
				finance_db.close();
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
